package com.atguigu.gmall.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class DeadMqConfing {
    //一个交换机  x-delayed-message  延迟
    //一个RouingKey
    //一个队列
    public static final String exchange_delay = "exchange.delay";
    public static final String routing_delay = "routing.delay";
    public static final String queue_delay_1 = "queue.delay.111";

    //基于插件的延迟交换机
    @Bean
    public Exchange sendDalyeExchange(){
        Map map=new HashMap<>();
        //指定是延迟类型，定向
        map.put("x-delayed-type","direct");

        //自定义交换机
        //参数1：交换机名  参数2：类型  参数3：是否持久化  参数4：是否删除  参数5：请求参数集合
        return  new CustomExchange(exchange_delay,"x-delayed-message",true,false,map);
    }

    @Bean
    public Queue sendDalyeQueue(){
        return QueueBuilder.durable(queue_delay_1).build();
    }

    @Bean
    public Binding bangding(@Qualifier("sendDalyeQueue")Queue sendDalyeQueue,@Qualifier(value = "sendDalyeExchange") Exchange sendDalyeExchange){
        return BindingBuilder.bind(sendDalyeQueue).to(sendDalyeExchange).with(routing_delay).noargs();
    }
}
